package com.projectName.www.dao;

import com.projectName.www.util.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DishcatagoryDaoImpl implements DishcatagoryDao {
    @Override
    public String queryBydid(Integer did) {

        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {

            connection = JDBCUtils.getConnection();//首先连接数据库

            String sql = "select vName from dishcatagory where vid=?";//写出sql语句




            preparedStatement = connection.prepareStatement(sql);//执行sql语句

            preparedStatement.setInt(1,did);

            resultSet = preparedStatement.executeQuery();//获得查询结果集


            if(resultSet.next()){
                return resultSet.getString(1);
            }

        } catch (SQLException e) {
            throw new DaoException(e.getMessage(),e);
        } finally {
            JDBCUtils.close(resultSet,preparedStatement,connection);
        }
        return null;
    }
}
